<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://amc.af.mil/portal-el" prefix="portal" %>
<%@ taglib uri="http://amc.af.mil/radtaglibrary" prefix="rad" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
<%@ taglib uri="http://struts.apache.org/tags-html-el" prefix="html" %>
<%@ taglib prefix="display" uri="http://displaytag.sf.net" %>
<html>
<head>
    <title>User Profile</title>
</head>

<body>

<div id="portal-left-bar">
    <jsp:include page="navigation/navigationMenu.jsp"/>
</div>

<rad:useBean id="adpeAccountViewHelper"/>
<rad:useBean id="drmoPackageViewHelper" />
<rad:useBean id="equipmentItemViewHelper"/>
<rad:useBean id="userViewHelper"/>
<rad:useBean id="handReceiptViewHelper"/>

<c:set var="drmoPackages" value="${requestScope.drmoPackageViewHelper.pendingByAdpeAccount}" />
<c:set var="adpeAccount" value="${adpeAccountViewHelper.adpeAccount}"/>

<div id="portal-content">
<div id="viewAccountProfile">
<portal:box title="View Profile" style="width: 100%">
<portal:subSection title="Choose ADPE Account">

    <html:form action="chooseAccount.do" method="post">
        <html:select property="newAdpeAccountId" value="${sessionScope.accountId}">
            <html:optionsCollection filter="false"
                                    name="adpeAccountViewHelper"
                                    property="adpeAccountsByAccount"
                                    label="name"
                                    value="id"/>
        </html:select>
        <html:submit title="Change Account"/>
    </html:form>
</portal:subSection>
<portal:subSection title="Main">
    <p>Account: <c:out value="${adpeAccount.name}"/></p>
    <p>DRA: <c:out value="${adpeAccount.dra.name}"/></p>
    <p>Total Items: <c:out value="${adpeAccountViewHelper.itemCount}"/></p>
    <p>Account Value: <fmt:formatNumber value="${adpeAccountViewHelper.accountValue}" type="currency"/>

</portal:subSection>
<portal:subSection title="Custodians">
    <display:table name="adpeAccountViewHelper.custodians"
                   style="text-align:center; width: 100%"
                   excludedParams="method"
                   id="custodian">
        <display:column title="Custodian Name">
            <c:out value="${custodian.displayName}"/>
        </display:column>
        <display:column title="Organization">
            <c:out value="${custodian.organization}"/>
        </display:column>
        <display:column title="CustodianType">
            <c:out value="${custodian.custodianType}"/>
        </display:column>
        <display:column title="Actions">
                <c:if test="${custodian.custodianType eq 1}">
                    <html:link href="javascript:confirmMakePrimary(${custodian.id}, ${adpeAccount.id});">
                        Make Primary
                    </html:link>
                    <html:link href="javascript:confirmRemoveCustodian(${custodian.id}, ${adpeAccount.id})">
                        Remove
                    </html:link>
                </c:if>
        </display:column>
    </display:table>
    <p style="text-align:right;">Add New Custodian</p>
</portal:subSection>
<portal:subSection title="Equipment">
    <display:table name="equipmentItemViewHelper.allCurrentByAccount"
                   style="text-align:center; width:100%"
                   requestURI="equipmentItemAction.do?method=prepareEquipmentListView"
                   pagesize="50"
                   excludedParams="method"
                   id="equipmentItem">
        <display:column title="Type"><c:out value="${equipmentItem.itemModel.type.name}"/>
        </display:column>
        <display:column title="Manufacturer"><c:out value="${equipmentItem.itemModel.manufacturer.name}"/>
        </display:column>
        <display:column title="Model">
            <html:link
                    href="equipmentItemAction.do?method=viewEquipmentItemByModelPage&modelId=${equipmentItem.itemModel.modelId}">
                <c:out value="${equipmentItem.itemModel.name}"/>
            </html:link>
        </display:column>
        <display:column title="Description"><c:out value="${equipmentItem.description}"/></display:column>
        <display:column title="Serial Number"><c:out value="${equipmentItem.serial}"/></display:column>
        <display:column title="Location">
            <div id="editLocationDiv-<c:out value="${equipmentItem.id}" />"
                 onclick="javascript:new Ajax.InPlaceEditor('editLocationDiv-<c:out value="${equipmentItem.id}" />', 'updateLocationInPlace.do?itemId=<c:out value="${equipmentItem.id}" />')">
                <c:choose>
                    <c:when test="${equipmentItem.location eq null}">
                        <i>Not Available</i>
                    </c:when>
                    <c:otherwise>
                        <c:out value="${equipmentItem.location}"/>
                    </c:otherwise>
                </c:choose>
            </div>
        </display:column>
        <display:column title="Assigned To">
            <div id=""></div>
            <%--<html:link href="viewUserProfile.do?userId=${equipmentItem.assignedUser.id}">--%>
            <c:out value="${equipmentItem.assignedUser.displayName}"/>
            <%--</html:link>--%>
        </display:column>
        <display:column title="Actions">
            <c:if test="${equipmentItem.assignedUser != null}">
                <html:link href="unassignItem.do?itemId=${equipmentItem.id}&userId=${equipmentItem.assignedUser.id}">
                    Unassign</html:link>
            </c:if>
            <html:link href="equipmentItemAction.do?method=viewItemPage&itemId=${equipmentItem.id}">
                View</html:link>
            <html:link href="equipmentItem/viewEdit.do?itemId=${equipmentItem.id}">
            <%--equipmentItemAction.do?method=viewEditItemPage&itemId=${equipmentItem.id}">--%>
                Edit</html:link>
        </display:column>

    </display:table>
</portal:subSection>
<portal:subSection title="Pending DRMO Packages">
    <p>Once a DRMO package is completed, it will no longer appear in this listing.</p>

    <display:table style="width: 800px"
                   name="drmoPackageViewHelper.pendingByAdpeAccount"
                   id="pkg">
        <display:column title="DTID" style="text-align:center" >
            <html:link href="viewDrmoPackage.do?packageId=${pkg.id}">
                <c:out value="${pkg.dtid}"/>
            </html:link>

        </display:column>
        <display:column title="Creation Date" style="text-align:center" >
            <fmt:formatDate value="${pkg.packageCreateDate}" type="date" pattern="d-MMM-y"/>
        </display:column>
        <display:column title="Total Items" style="text-align:center" >
           <c:out value="${pkg.packageSize}"/>
        </display:column>
        <display:column title="Actions" style="text-align:center">
            <c:choose>
                <c:when test="${pkg.status ne 'OPEN'}">
                    <c:out value="${pkg.status}"/>
                    <html:link href="viewEditDrmoPackage.do?input=accountProfile&packageId=${pkg.id}">Edit</html:link>
                    <html:link href="javascript:confirmDeleteDrmoPackage(${pkg.id},'${pkg.name}');">Delete</html:link>
                    <html:link href="javascript:confirmCloseDrmoPackage(${pkg.id}, '${pkg.name}');">Close</html:link>
                </c:when>
                <c:otherwise>
                    <html:link href="viewDrmoPackage.do?packageId=${pkg.id}">View</html:link>
                </c:otherwise>
            </c:choose>
        </display:column>
    </display:table>
</portal:subSection>
<portal:subSection title="Current Hand Receipts">

    <display:table name="handReceiptViewHelper.allByAdpeAccount"
                   style="width:100%"
                   id="hr">
        <display:column title="Name">
            <html:link href="viewHandReceipt.do?hrId=${hr.id}">
                <c:out value="${hr.name}" />
            </html:link>
        </display:column>
        <display:column property="issueDate" title="Issue Date" />
        <display:column property="returnDate" title="Return Date" />
        <display:column property="itemCount" title="Items" />
        <display:column title="Actions">
            <html:link href="javascript:confirmCloseHandReceipt(${hr.id},${hr.name}">Close</html:link>
            <html:link href="create1297.do?hrId=${hr.id}">1297</html:link>
        </display:column>
    </display:table>

</portal:subSection>
</portal:box>
</div>
</div>
</body>
</html>